<?php


namespace Home\DAO;


class TaobaoTradesDAO extends PSIBaseExDAO
{
    public function addorder(&$params)
    {
        $db = $this->db;

//        $id = $this->newId();
        $sql = "insert ignore into t_taobao_trades(adjust_fee, no_shipping, buyer_rate, cid,consign_time,discount_fee,divide_order_fee,invoice_no,is_daixiao,logistics_company,num,num_iid,oid,outer_sku_id,part_mjz_discount,
            payment, pic_path, price,refund_status,seller_rate,seller_type,shipping_type,sku_id,sku_properties_name,status,title,total_fee,tid,`type`,issd,sdtime,receiver_mobile,receiver_phone,
            receiver_name,buyer_nick,has_buyer_message,o2o_guide_id,o2o_guide_name,end_time,create_time)
            values ('%s', '%s', '%s', '%s','%s', '%s', '%s', '%s','%s', '%s', '%s','%s', '%s', '%s', '%s','%s', '%s', '%s','%s', '%s', '%s', '%s','%s', '%s', '%s', '%s',
            '%s', '%s','%s','%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s','%s','%s')"; // 39

//        $sql = $db->prepare("insert into t_taobao_trades(no_shipping, adjust_fee, buyer_rate, cid,consign_time,discount_fee,divide_order_fee,invoice_no,is_daixiao,logistics_company,num,num_iid,oid,outer_sku_id,part_mjz_discount,
//            payment, pic_path, price,refund_status,seller_rate,seller_type,shipping_type,sku_id,sku_properties_name,status,title,total_fee,tid,`type`,issd,sdtime,create_time)
//            values (?,?,?,?,?,?,?,?, ?,?,?,?,?,?,?,?, ?,?,?,?,?,?,?,?, ?,?,?,?,?,?,?,?,)"); // 32
//        $sql->bind_param("ssssssssssssssssssssssssssssss",
//            $param['no_shipping'], $param['adjust_fee'], $param['buyer_rate'],$param['cid'],$param['consign_time'], $param['discount_fee'],$param['divide_order_fee'],$param['invoice_no'],
//                $param['is_daixiao'],$param['logistics_company'],$param['num'],$param['num_iid'],$param['oid'],$param['outer_sku_id'],$param['part_mjz_discount'],
//                $param['payment'],$param['pic_path'],$param['price'],$param['refund_status'],$param['seller_rate'],$param['seller_type'],$param['shipping_type'],$param['sku_id'],
//                $param['sku_properties_name'],$param['status'],$param['title'],$param['total_fee'],$param['tid'],$param['type'],'raw',date('Y-m-d H:i:s'),date('Y-m-d H:i:s'));
        foreach ($params as $value)
        {

//            $param = array_merge($value['orders']['order'],$value);
//            unset($param['orders']);

            foreach ($value['orders']['order'] as $val) {
                $param = array_merge($value,$val);
                unset($param['orders']);
//                $sql->execute();
                $rc = $db->execute($sql,
                $param['adjust_fee'], $param['no_shipping'], $param['buyer_rate'],$param['cid'],$param['consign_time'], $param['discount_fee'],$param['divide_order_fee'],$param['invoice_no'],
                $param['is_daixiao'],$param['logistics_company'],$param['num'],$param['num_iid'],$param['oid'],$param['outer_sku_id'],$param['part_mjz_discount'],
                $param['payment'],$param['pic_path'],$param['price'],$param['refund_status'],$param['seller_rate'],$param['seller_type'],$param['shipping_type'],$param['sku_id'],
                $param['sku_properties_name'],$param['status'],$param['title'],$param['total_fee'],$param['tid'],$param['type'],'raw',date('Y-m-d H:i:s'),$param['receiver_mobile'],
                $param['receiver_phone'],$param['receiver_name'],$param['buyer_nick'],$param['has_buyer_message'],$param['o2o_guide_id'],$param['o2o_guide_name'],$param['end_time'],date('Y-m-d H:i:s') //32
            );//注意第一个值不能为bool类型，后面model.class.php会检测第一个值，是bool则没有预执行。

                if ($rc === false) {
                    return $this->sqlError(__METHOD__, __LINE__);
                }
//                var_dump($this->db->getLastSql());
            }

        }
//        $rc =
//        if ($rc === false) {
//            return $this->sqlError(__METHOD__, __LINE__);
//        }

        // 操作成功
//        $params["id"] = $id;
        return null;
    }
    //搜索当前会话用户作为卖家已卖出的增量交易数据（只能获取到三个月以内的交易信息）
    //$db->execute() 内匹配的是增量交易数据
    public function incrementv(&$params)
    {
        $db = $this->db;

//        $id = $this->newId();
        $sql = "insert into t_taobao_trades(no_shipping, adjust_fee, buyer_rate, cid,consign_time,discount_fee,divide_order_fee,end_time,invoice_no,is_daixiao,logistics_company,num,num_iid,oid,outer_sku_id,part_mjz_discount,
            payment, pic_path, price,refund_status,seller_rate,seller_type,shipping_type,sku_id,sku_properties_name,status,title,total_fee,tid,`type`,issd,sdtime,create_time)
            values ('%s', '%s', '%s', '%s','%s', '%s', '%s', '%s','%s', '%s', '%s', '%s','%s', '%s', '%s', '%s','%s', '%s', '%s', '%s','%s', '%s', '%s', '%s','%s', '%s', '%s', '%s',
            '%s', '%s',date('Y-m-d H:i:s'))";
        foreach ($params as $value)
        {

//            $param = array_merge($value['orders']['order'],$value);
//            unset($param['orders']);

            foreach ($value['orders']['order'] as $val) {
                $param = array_merge($value,$val);
                unset($param['orders']);
                var_dump($param);
            }
//            $db->execute($sql,
//                $param['no_shipping'], $param['adjust_fee'], $param['buyer_rate'],$param['cid'],$param['consign_time'], $param['discount_fee'],$param['divide_order_fee'],$param['end_time'],
//                $param['invoice_no'],$param['is_daixiao'],$param['logistics_company'],$param['num'],$param['num_iid'],$param['oid'],$param['outer_sku_id'],$param['part_mjz_discount'],
//                $param['payment'],$param['pic_path'],$param['price'],$param['refund_status'],$param['seller_rate'],$param['seller_type'],$param['shipping_type'],$param['sku_id'],
//                $param['sku_properties_name'],$param['status'],$param['title'],$param['total_fee'],$param['tid'],$param['type'],$param['issd']
//            );
        }
//        $rc =
//        if ($rc === false) {
//            return $this->sqlError(__METHOD__, __LINE__);
//        }

        // 操作成功
//        $params["id"] = $id;
        return null;
    }

}